package com.kung.qvs.data.source.local;

import com.kung.qvs.data.source.LocalDataSource;
import com.kung.qvs.utils.RetrofitClient;

import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * 本地数据源，可配合Room框架使用
 * Created by goldze on 2019/3/26.
 */
public class LocalDataSourceImpl implements LocalDataSource {
    private volatile static LocalDataSourceImpl INSTANCE = null;

    public static LocalDataSourceImpl getInstance() {
        if (INSTANCE == null) {
            synchronized (LocalDataSourceImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new LocalDataSourceImpl();
                }
            }
        }
        return INSTANCE;
    }

    public static void destroyInstance() {
        INSTANCE = null;
    }

    private LocalDataSourceImpl() {
        //数据库Helper构建
    }

    @Override
    public void saveUserName(String userName) {
        SPUtils.getInstance().put("UserName", userName);
    }

    @Override
    public void savePassword(String password) {
        SPUtils.getInstance().put("password", password);
    }

    @Override
    public String getUserName() {
        return SPUtils.getInstance().getString("UserName");
    }

    @Override
    public String getPassword() {
        return SPUtils.getInstance().getString("password");
    }

    @Override
    public void saveAccount(String account) {
        SPUtils.getInstance().put("account", account);
    }

    @Override
    public String getAccount() {
        return SPUtils.getInstance().getString("account");
    }

    @Override
    public void saveLoginState(Boolean state) {
        SPUtils.getInstance().put("loginState", state);
    }

    @Override
    public boolean getLoginState() {
        return SPUtils.getInstance().getBoolean("loginState");
    }

    @Override
    public void saveKeepPwd(Boolean state) {
        SPUtils.getInstance().put("keepPwd", state);
    }

    @Override
    public boolean getKeepPwd() {
        return SPUtils.getInstance().getBoolean("keepPwd");
    }

    @Override
    public void saveBaseUrl(String baseUrl) {
        SPUtils.getInstance().put("baseurl", baseUrl);
    }

    @Override
    public String getBaseUrl() {
        return SPUtils.getInstance().getString("baseurl", RetrofitClient.baseUrl);
    }

    @Override
    public void saveConvertGreyImgByFloyd(String convertGreyImgByFloyd) {
        SPUtils.getInstance().put("convertGreyImgByFloyd", convertGreyImgByFloyd);
    }

    @Override
    public String getConvertGreyImgByFloyd() {
        return SPUtils.getInstance().getString("convertGreyImgByFloyd");
    }

    @Override
    public void saveEquipmentNo(String equipmentNo) {
        SPUtils.getInstance().put("equipmentNo", equipmentNo);
    }

    @Override
    public String getEquipmentNo() {
//        return "M022112302600046";
//        return "DZC00001";
        return SPUtils.getInstance().getString("equipmentNo");
    }

    @Override
    public void saveOriginPlace(String originPlace) {
        SPUtils.getInstance().put("originPlace", originPlace);
    }

    @Override
    public String getOriginPlace() {
        return SPUtils.getInstance().getString("originPlace");
    }

    @Override
    public void saveProducer(String producer) {
        SPUtils.getInstance().put("producer", producer);
    }

    @Override
    public String getProducer() {
        return SPUtils.getInstance().getString("producer");
    }

    @Override
    public void saveContact(String contact) {
        SPUtils.getInstance().put("contact", contact);
    }

    @Override
    public String getContact() {
        return SPUtils.getInstance().getString("contact");
    }

    @Override
    public void saveTare(String tare) {
        SPUtils.getInstance().put("tare", tare);
    }

    @Override
    public String getTare() {
        return SPUtils.getInstance().getString("tare", "0");
    }

    @Override
    public void saveCompanyName(String companyName) {
        SPUtils.getInstance().put("companyName", companyName);
    }

    @Override
    public String getCompanyName() {
        return SPUtils.getInstance().getString("companyName");
    }

    @Override
    public void saveProduct(String product) {
        SPUtils.getInstance().put("product", product);
    }

    @Override
    public String getProduct() {
        return SPUtils.getInstance().getString("product");
    }

    @Override
    public void saveLoginType(String loginType) {
        SPUtils.getInstance().put("loginType", loginType);
    }

    @Override
    public String getLoginType() {
        return SPUtils.getInstance().getString("loginType");
    }
}
